import sys
import math
import typing
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets
from EnemySet import EnemySet
from EnemySmallMoving import Small_Moving


class AllEnemy:
    def __init__(self, scene):
        self.EnemySetList = []
        self.SpeedList = [5, 5, 5]
        self.RotateList = [20, 135, -135, 160, 30, -45, -120, 45, -180, -160]
        self.StartXList = [-120, 1200, 1200, 1600, -120, 30, 1000, 800, 1600, 1600]
        self.StartYList = [20, 0, 930, 300, 300, 930, 930, 0, 300, 1000]

        self.SpeedList1 = [5, 5, 5]
        self.RotateList1 = [20, 135, -135, 160, 30, -45, -120, 45, -180, -160]
        self.StartXList1 = [-120, 1200, 1200, 1600, -120, 30, 1000, 800, 1600, 1600]
        self.StartYList1 = [20, 0, 930, 300, 300, 930, 930, 0, 300, 1000]

        self.SpeedList2 = [6, 6, 4]
        self.RotateList2 = [0, 135, -135, 160, 30, -45, -120, 45, -180, -160]
        self.StartXList2 = [-120, 1200, 1200, 1600, -120, 30, 1000, 800, 1600, 1600]
        self.StartYList2 = [20, 0, 930, 300, 300, 930, 930, 0, 300, 1000]

        self.SpeedList3 = [7, 7, 3]
        self.RotateList3 = [20, 135, -135, 160, 30, -45, -120, 45, -180, -160]
        self.StartXList3 = [-120, 1200, 1200, 1600, -120, 30, 1000, 800, 1600, 1600]
        self.StartYList3 = [20, 0, 930, 300, 300, 930, 930, 0, 300, 1000]

        self.levelSymbol = 1

        self.AllSpeedList = [self.SpeedList1, self.SpeedList2, self.SpeedList3]
        self.AllRotateList = [self.RotateList1, self.RotateList2, self.RotateList3]
        self.AllStartXList = [self.StartXList1, self.StartXList2, self.StartXList3]
        self.AllStartYList = [self.StartYList1, self.StartYList2, self.StartYList3]

        self.callTime = 0  # 记录第几次调用
        self.callTimetwo = 0
        self.callBulletTime = 0  # 记录调用敌人子弹集合
        self.levelSymbol = 1
        for i in range(10):  # 设置基础敌人集合
            self.EnemySetList.append(EnemySet(scene))  # 实例化集合

        for i in range(10):
            self.EnemySetList.append(EnemySet(scene))  # 后两个EnemySet指的是FollowEnemySet

        for i in range(10):
            self.EnemySetList.append(EnemySet(scene))

        for i in range(10):
            self.EnemySetList.append(EnemySet(scene))

        for i in range(20):
            self.EnemySetList.append(EnemySet(scene))

    def SetLevelSymbol(self, Symbol):
        self.levelSymbol = Symbol
        self.SpeedList = self.AllSpeedList[Symbol - 1]
        self.RotateList = self.AllRotateList[Symbol - 1]
        self.StartXList = self.AllStartXList[Symbol - 1]
        self.StartYList = self.AllStartYList[Symbol - 1]

    def CallSmallEnemy(self):
        self.EnemySetList[self.callTimetwo + 40].setOneSmallEnemy(self.SpeedList[self.levelSymbol], self.RotateList[self.callTimetwo % 10],
                                                                  self.StartXList[self.callTimetwo % 10],
                                                                  self.StartYList[self.callTimetwo % 10])
        self.callTimetwo = (self.callTimetwo + 1) % 20
        # self.callTime = (self.callTime + 1) % 10

    def CallSmallEnemySet(self):
        # 用来产生小人，并将其设为可视

        self.EnemySetList[self.callTime].setSmallEnemy(self.SpeedList[self.levelSymbol], self.RotateList[self.callTime],
                                                       self.StartXList[self.callTime],
                                                       self.StartYList[self.callTime])  # 对集合进行设置，并使其可视
        self.callTime = (self.callTime + 1) % 10

    def CallFollowEnemySet(self):
        self.EnemySetList[self.callTime + 10].SetFollowEnemy(self.SpeedList[self.levelSymbol],
                                                             self.RotateList[self.callTime],
                                                             self.StartXList[self.callTime],
                                                             self.StartYList[self.callTime])  # 对集合进行设置，并使其可视
        self.callTime = (self.callTime + 1) % 10

    def CallBigEnemySet(self):
        self.EnemySetList[self.callTime + 20].setBigEnemy(self.SpeedList[self.levelSymbol], self.RotateList[self.callTime],
                                                          self.StartXList[self.callTime],
                                                          self.StartYList[self.callTime])  # 对集合进行设置，并使其可视
        self.callTime = (self.callTime + 1) % 10

    def CallEnemyBullet(self, StartX, StartY, Rotate):
        self.callBulletTime = (self.callBulletTime + 1) % 10
        self.EnemySetList[self.callBulletTime + 30].setEnemyBullet(10, Rotate, StartX, StartY)
